﻿using System;

namespace Cpu6502.Opcodes
{
    /// <summary>
    /// STA $AAAA - Store Accumulator Absolute Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_A : Opcode
    {
        public STA_A()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.Absolute;
        }

        public override void Execute()
        {            
            CPU.Memory[base.Argument] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA $AAAA,X - Store Accumulator Absolute X Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_A_X : Opcode
    {
        public STA_A_X()
        {
            this.CpuCycles = 5;
            this.AddressType = CPU.AddressType.AbsoluteIndexedX;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument,CPU.AddressType.AbsoluteIndexedX)
                ] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA $AAAA,Y - Store Accumulator Absolute Y Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_A_Y : Opcode
    {
        public STA_A_Y()
        {
            this.CpuCycles = 5;
            this.AddressType = CPU.AddressType.AbsoluteIndexedY;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.AbsoluteIndexedY)
                ] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA $AA - Store Accumulator Zeropage Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_ZP : Opcode
    {
        public STA_ZP()
        {
            this.CpuCycles = 3;
            this.AddressType = CPU.AddressType.ZeroPage;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.ZeroPage)
                ] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA $AA, X - Store Accumulator Zeropage X Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_ZP_X : Opcode
    {
        public STA_ZP_X()
        {
            this.CpuCycles = 4;
            this.AddressType = CPU.AddressType.ZeroPageIndexedX;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.ZeroPageIndexedX)
                ] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA ($AA, X) - Store Accumulator Indexed Indirect Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_Indexed_Indirect : Opcode
    {
        public STA_Indexed_Indirect()
        {
            this.CpuCycles = 6;
            this.AddressType = CPU.AddressType.IndexedIndirect;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.IndexedIndirect)
                ] = CPU.Registers.A;
        }
    }

    /// <summary>
    /// STA ($AA), Y - Store Accumulator Indirect Indexed Mode
    /// Stores Acumulator in memory address
    /// </summary>
    class STA_Indirect_Indexed : Opcode
    {
        public STA_Indirect_Indexed()
        {
            this.CpuCycles = 6;
            this.AddressType = CPU.AddressType.IndirectIndexed;
        }

        public override void Execute()
        {
            CPU.Memory
                [
                    MemoryHelper.GetAddress
                    (base.Argument, CPU.AddressType.IndirectIndexed)
                ] = CPU.Registers.A;
        }
    }
}
